package com.sukaiyi.generator.ui.base;

import com.sukaiyi.generator.utils.ProjectUtils;
import com.intellij.openapi.ui.DialogWrapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

public class InputChooseDialog extends DialogWrapper {
    private JTextField nameTextField;
    private JComboBox<String> typeComboBox;
    private JPanel rootPanel;

    public InputChooseDialog(String[] options) {
        super(ProjectUtils.getProject());
        this.init();
        this.setTitle("Create New Node");
        typeComboBox.setModel(new DefaultComboBoxModel<>(options));
    }

    @Nullable
    @Override
    protected JComponent createCenterPanel() {
        return rootPanel;
    }

    public void setOptions(String[] options){
        typeComboBox.setModel(new DefaultComboBoxModel<>(options));
    }

    public void setValue(NodeInfo nodeInfo) {
        nameTextField.setText(nodeInfo.getName());
        typeComboBox.setSelectedItem(nodeInfo.getType());
    }

    public NodeInfo getValue() {
        NodeInfo nodeInfo = new NodeInfo();
        nodeInfo.setName(nameTextField.getText());
        nodeInfo.setType((String) typeComboBox.getSelectedItem());
        return nodeInfo;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class NodeInfo {
        private String name;
        private String type;
    }
}
